package com.example.pushmessage.controller;

import com.alibaba.fastjson.JSON;
import com.example.pushmessage.controller.websocket.WebSocketServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.Map;


@RestController
public class Consumer {

    Logger logger = LoggerFactory.getLogger(getClass());

//    @RabbitHandler
//    @RabbitListener(queues = "wisdom_queue_message")//监听的队列名称 TestDirectQueue
    public void test(Map map) {
        String message = JSON.toJSONString(map);
        logger.info("rabbitmq信息 : {}", message);

        try {
            //调用方法推送消息
            WebSocketServer.sendInfo(message,map.get("userId").toString());
        } catch (IOException e) {
            logger.error("消息发送失败");
        }
    }

}
